import { createRouter, createWebHashHistory } from 'vue-router'
//配置路由地址和路由组件对应关系
import Index from '@/views/web/index.vue'
import Login from '@/views/admin/login.vue'
import Admin from '@/layouts/admin/admin.vue'
const routes = [
    {
        path: '/login', // 登录页
        component: Login,
        meta: {
            title: 'Weblog 登录页'
        }
    },
    {
        path: '/wiki/list', // 知识库
        component: () => import('@/views/web/wiki-list.vue'),
        meta: {
            title: '知识库'
        }
    },
    {
        path: '/wiki/:wikiId', // 知识库详情页
        component: () => import('@/views/web/wiki-detail.vue'),
        meta: {
            title: '知识库详情'
        }
    },
    {
        path: '/tag/article/list', // 标签列表页
        component: () => import('@/views/web/tag-article-list.vue'),
        meta: { // meta 信息
            title: 'Weblog 标签文章页'
        }
    },
    {
        path: '/article/:articleId', // 文章详情页
        component: () => import('@/views/web/article-detail.vue'),
        meta: { // meta 信息
            title: 'Weblog 详情页'
        }
    },
    {
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        component: () => import('@/views/web/404.vue'),
        meta: {
            title: '404 页'
        }
    },
    {
        path: '/archive/list', // 归档页
        component: () => import('@/views/web/archive-list.vue'),
        meta: { // meta 信息
            title: 'Weblog 归档页'
        }
    },
    {
        path: '/tag/list', // 标签列表页
        component: () => import('@/views/web/tag-list.vue'),
        meta: { // meta 信息
            title: 'Weblog 标签列表页'
        }
    },
    {
        path: '/category/article/list', // 分类文章页
        component: () => import('@/views/web/category-article-list.vue'),
        meta: { // meta 信息
            title: 'Weblog 分类文章页'
        }
    },
    {
        path: '/category/list', // 分类页
        component: () => import('@/views/web/category-list.vue'),
        meta: { // meta 信息
            title: 'Weblog 分类页'
        }
    },
    {
        path: '/', // 路由地址，首页
        component: Index, // 对应组件
        meta: { // meta 信息
            title: 'Weblog 首页' // 页面标题
        }
    },
    {
        path: "/admin", // 后台首页
        component: Admin,
        // 使用到 admin.vue 布局的，都需要放置在其子路由下面
        children: [
            {
                path: "/admin/index",
                component: () => import('@/views/admin/index.vue'),
                meta: {
                    title: '仪表盘'
                }
            },
            {
                path: "/admin/comment/list",
                component: () => import('@/views/admin/comment-list.vue'),
                meta: {
                    title: '评论管理'
                }
            },
            {
                path: "/admin/wiki/list",
                component: () => import('@/views/admin/wiki-list.vue'),
                meta: {
                    title: '知识库管理'
                }
            },
            {
                path: "/admin/article/list",
                component: () => import('@/views/admin/article-list.vue'),
                meta: {
                    title: '文章管理'
                }
            },
            {
                path: "/admin/category/list",
                component: () => import('@/views/admin/category-list.vue'),
                meta: {
                    title: '分类管理'
                }
            },
            {
                path: "/admin/tag/list",
                component: () => import('@/views/admin/tag-list.vue'),
                meta: {
                    title: '标签管理'
                }
            },
            {
                path: "/admin/blog/setting",
                component: () => import('@/views/admin/blog-setting.vue'),
                meta: {
                    title: '博客设置'
                }
            },
        ]
    }

]

//创建路由实列 导入配置项
const router = createRouter({
    routes,
    history: createWebHashHistory(),
    // 每次切换路由后，页面滚动到顶部
    scrollBehavior() {
        return { top: 0 }
    }
})

//到处路由实列
export default router